<template>
  <el-dialog
      title="编辑项目"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
    <el-form :model="form" :rules="rules" ref="formRef" label-width="120px" class="demo-ruleForm">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="form.project_name" autocomplete="off"/>
      </el-form-item>
      <el-form-item label="井名称" prop="wellName">
        <!--这个井是个下拉框，下拉框的内容从后端获取-->
        <el-select v-model="form.well_ids" multiple placeholder="请选择井名称">
          <el-option
              v-for="item in wellList"
              :key="item.id"
              :label="item.well_name"
              :value="item.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="updateProject">确 定</el-button>
  </span>
  </el-dialog>
</template>
<script>
import api from "@/api/api";
export default {
  data(){
    return {
      dialogVisible: false,
      form: {
        project_name: '',
        well_ids: [],
        n: '',
        vp: '',
        vs: '',
        ucs: '',
        o: '',
      },
      // 接收井的信息
      wellList: [],
      rules: {
        project_name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' },
        ],
        well_id: [
          { required: true, message: '请选择井名称', trigger: 'blur' },
        ],
      },
    }
  },
  methods:{
    handleClose(){
      this.dialogVisible = false
    },
    updateProject() {
      const params = {
        id: this.form.id,
        project_name: this.form.project_name,
        well_ids: this.form.well_ids,
        n: this.form.n,
        vp: this.form.vp,
        vs: this.form.vs,
        ucs: this.form.ucs,
        o: this.form.o,
      }
      api.post('/project/updateProject', params).then(res => {
        if (res.data.code === 0) {
          this.$message({
            message: '更新成功',
            type: 'success'
          })
          this.dialogVisible = false
          //调用父类的方法刷新页面
          this.$emit('updateProjectSuccess');
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>